package labuladong.leetcode.editor.cn._00bean;

/**
 * @author weibin
 * @create 2022-11-28 19:55
 */
public class ListNode {
    public int val;
    public ListNode next;

    public ListNode() {
    }

    public ListNode(int val) {
        this.val = val;
    }

    public ListNode(int val, ListNode next) {
        this.val = val;
        this.next = next;
    }

    @Override
    public String toString() {
        StringBuffer sb = new StringBuffer();
        ListNode node = this;
        while (node != null) {
            if (node.next == null) {  //链表最后一个节点
                sb.append(String.valueOf(node.val));
                break;
            }
            sb.append(String.valueOf(node.val));
            sb.append("->");
            node = node.next;
        }
        return String.valueOf(sb);
    }

//    @Override
//    public String toString() {
//        return String.valueOf(this.val);
//    }
}
